{% extends 'user/product_base.html' %}

{% block content %}
 <section class="slice pt-2 bg-surface-secondary">
    <div class="container mt-4 mb-5 pl-6  ">
        <div class="row">
            <div class="col col-md-3 mb-sm-4">
                <div class="col col-md12">
                    <div class="card-header pb-2 list-group-item-info">
                        个人信息
                    </div>
                    <ul class="list-group list-group-flush" id="myList">
                        <li class="list-group-item"><a href="{{ url_for('users.userInfo') }}" class="link-primary">个人资料</a></li>
                        <li class="list-group-item"><a href="{{ url_for('address.address_management') }}" class="link-primary">地址管理</a></li>
                        <li class="list-group-item" style="background-color: #cefaff;"><a href="{{ url_for('user.order_management') }}" class="link-primary">订单管理</a></li>
                        <li class="list-group-item">
                            <a href="{{ url_for('story.upload_story') }}" class="link-primary">上传故事管理</a>
                        </li>
                    </ul>
                    <div class="card-footer pb-2 list-group-item-info">
                        <p></p>
                    </div>
                </div>
            </div>
            <div class="col col-md-8 col-sm-12 ml-2 p-5 resume_box_body">
                <div class="container my-4">
                    <!-- 新增：Flash 消息显示区域 -->
                    <div class="flash-messages">
                        {% with messages = get_flashed_messages(with_categories=true) %}
                            {% if messages %}
                                {% for category, message in messages %}
                                    <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
                                        {{ message }}
                                        <button type="button" class="close" data-bs-dismiss="alert" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                    </div>
                                {% endfor %}
                            {% endif %}
                        {% endwith %}
                    </div>
        <h1 class="mb-4">订单详情</h1>

        {% if user %}
            <p>欢迎, {{ user.username }}!</p>  <!-- 显示用户的用户名 -->
        {% else %}
            <p>您未登录，请<a href="{{ url_for('login.login') }}">登录</a>以查看更多信息。</p>
        {% endif %}

        <div class="order-details">
            <h3>订单编号: {{ order.id }}</h3>
            <p>下单时间: {{ order.order_time.strftime('%Y-%m-%d %H:%M:%S') }}</p>
            {% set status_map = {
                'paid': '已支付',
                'unpaid': '未支付',
            } %}
            <p>订单状态: {{ status_map[order.status] }}</p>
            {% if order.status == 'unpaid' %}
              <form action="{{ url_for('cart.checkout') }}" method="POST">
                <input type="hidden" name="order_id" value="{{ order.id }}">
                <button type="submit" class="btn btn-sm btn-primary">立即付款</button>
              </form>
            {% endif %}
            <p>收货地址: {{ order.address }}</p>  <!-- 显示地址 -->
            <p>收件人: {{ order.recipient_name }}</p>  <!-- 显示收件人 -->
            <p>手机号: {{ order.phone }}</p>  <!-- 显示手机号 -->
            <h4>商品列表</h4>
            <table class="table">
                <thead>
                    <tr>
                        <th>商品</th>
                        <th>单价</th>
                        <th>数量</th>
                        <th>小计</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in order_items %}
                    <tr>
                        <td>{{ item.flower.name }}</td>
                        <td>¥{{ "%.2f"|format(item.price) }}</td>
                        <td>{{ item.quantity }}</td>
                        <td>¥{{ "%.2f"|format(item.price * item.quantity) }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="3" class="text-end"><strong>总计:</strong></td>
                        <td><strong>¥{{ "%.2f"|format(order_total) }}</strong></td>
                    </tr>
                </tfoot>
            </table>
            <a href="{{ url_for('user.order_management') }}" class="btn btn-primary">返回订单列表</a>
            <a href="{{ url_for('flower.product') }}" class="btn btn-primary">继续购物</a>
        </div>
    </div>
            </div>
        </div>
    </div>
</section>
{% endblock %} 